home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / VISCAFE.BIN / ScrollingPanel.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-06-19  |  7.4 KB  |  466 lines

  1. package symantec.itools.awt;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Event;
  7. import java.awt.Graphics;
  8. import java.awt.LayoutManager;
  9. import java.awt.Rectangle;
  10. import java.awt.Scrollbar;
  11. import symantec.itools.awt.shape.Rect;
  12. import symantec.itools.lang.OS;
  13.  
  14. public class ScrollingPanel extends KeyPressManagerPanel {
  15.    private Component spComponent;
  16.    private int width;
  17.    private int height;
  18.    private int xCoord;
  19.    private int yCoord;
  20.    private Scrollbar VBar;
  21.    private Scrollbar HBar;
  22.    private boolean bVBarVisible;
  23.    private boolean bHBarVisible;
  24.    private boolean bCornerRectVisible;
  25.    private int vPageSize;
  26.    private int hPageSize;
  27.    private Dimension dimComponent;
  28.    private int vGapWid;
  29.    private int hGapHt;
  30.    private boolean bAllowShowVBar;
  31.    private boolean bAllowShowHBar;
  32.    private int scrollLineIncrement;
  33.    private Rect cornerRect;
  34.  
  35.    public ScrollingPanel() {
  36.       this((Component)null, 0, 0);
  37.    }
  38.  
  39.    public ScrollingPanel(Component var1, int var2, int var3) {
  40.       this.bAllowShowVBar = true;
  41.       this.bAllowShowHBar = true;
  42.       this.scrollLineIncrement = 1;
  43.       this.spComponent = var1;
  44.       this.width = var2;
  45.       this.height = var3;
  46.       this.xCoord = 0;
  47.       this.yCoord = 0;
  48.       this.bVBarVisible = false;
  49.       this.bHBarVisible = false;
  50.       this.bCornerRectVisible = false;
  51.       this.vPageSize = 0;
  52.       this.hPageSize = 0;
  53.       this.vGapWid = 6;
  54.       this.hGapHt = 6;
  55.       this.dimComponent = new Dimension(0, 0);
  56.       this.VBar = new Scrollbar();
  57.       this.VBar.setBackground(Color.lightGray);
  58.       this.HBar = new Scrollbar(0);
  59.       this.HBar.setBackground(Color.lightGray);
  60.       this.cornerRect = new Rect();
  61.       this.cornerRect.setForeground(Color.lightGray);
  62.       this.cornerRect.setFillColor(Color.lightGray);
  63.       this.cornerRect.setFillMode(true);
  64.       this.setLayout((LayoutManager)null);
  65.       this.addInternalComponents();
  66.       this.VBar.hide();
  67.       this.HBar.hide();
  68.       this.cornerRect.hide();
  69.       if (this.spComponent != null) {
  70.          super.add(this.spComponent, -1);
  71.          this.placeComponents();
  72.       }
  73.  
  74.    }
  75.  
  76.    public void setMinimumWidth(int var1) {
  77.       this.width = var1;
  78.    }
  79.  
  80.    public int getMinimumWidth() {
  81.       return this.width;
  82.    }
  83.  
  84.    public void setMinimumHeight(int var1) {
  85.       this.height = var1;
  86.    }
  87.  
  88.    public int getMinimumHeight() {
  89.       return this.height;
  90.    }
  91.  
  92.    public void setVerticalGap(int var1) {
  93.       this.vGapWid = var1;
  94.       ((Component)this).invalidate();
  95.    }
  96.  
  97.    public int getVerticalGap() {
  98.       return this.vGapWid;
  99.    }
  100.  
  101.    public void setHorizontalGap(int var1) {
  102.       this.hGapHt = var1;
  103.       ((Component)this).invalidate();
  104.    }
  105.  
  106.    public int getHorizontalGap() {
  107.       return this.hGapHt;
  108.    }
  109.  
  110.    public void setShowVerticalScroll(boolean var1) {
  111.       if (this.bAllowShowVBar != var1) {
  112.          this.bAllowShowVBar = var1;
  113.          ((Component)this).invalidate();
  114.       }
  115.  
  116.    }
  117.  
  118.    public boolean getShowVerticalScroll() {
  119.       return this.bAllowShowVBar;
  120.    }
  121.  
  122.    public void setShowHorizontalScroll(boolean var1) {
  123.       if (this.bAllowShowHBar != var1) {
  124.          this.bAllowShowHBar = var1;
  125.          ((Component)this).invalidate();
  126.       }
  127.  
  128.    }
  129.  
  130.    public boolean getShowHorizontalScroll() {
  131.       return this.bAllowShowHBar;
  132.    }
  133.  
  134.    public void setScrollLineIncrement(int var1) {
  135.       this.scrollLineIncrement = var1;
  136.    }
  137.  
  138.    public int getScrollLineIncrement() {
  139.       return this.scrollLineIncrement;
  140.    }
  141.  
  142.    public void setComponent(Component var1) {
  143.       super.removeAll();
  144.       if (this.spComponent != null) {
  145.          super.remove(this.spComponent);
  146.       }
  147.  
  148.       this.spComponent = var1;
  149.       super.add(this.spComponent, -1);
  150.       this.addInternalComponents();
  151.       ((Component)this).invalidate();
  152.    }
  153.  
  154.    public Component getComponent() {
  155.       return this.spComponent;
  156.    }
  157.  
  158.    public boolean handleEvent(Event var1) {
  159.       if (var1.target == this.HBar || var1.target == this.VBar) {
  160.          switch (var1.id) {
  161.             case 601:
  162.                if (var1.target == this.HBar) {
  163.                   this.scrollLeft();
  164.                } else {
  165.                   this.scrollUp();
  166.                }
  167.  
  168.                return true;
  169.             case 602:
  170.                if (var1.target == this.HBar) {
  171.                   this.scrollRight();
  172.                } else {
  173.                   this.scrollDown();
  174.                }
  175.  
  176.                return true;
  177.             case 603:
  178.                if (var1.target == this.HBar) {
  179.                   this.scrollPageLeft();
  180.                } else {
  181.                   this.scrollPageUp();
  182.                }
  183.  
  184.                return true;
  185.             case 604:
  186.                if (var1.target == this.HBar) {
  187.                   this.scrollPageRight();
  188.                } else {
  189.                   this.scrollPageDown();
  190.                }
  191.  
  192.                return true;
  193.             case 605:
  194.                if (var1.target == this.HBar) {
  195.                   this.scrollHorizontalAbsolute((Integer)var1.arg);
  196.                } else {
  197.                   this.scrollVerticalAbsolute((Integer)var1.arg);
  198.                }
  199.  
  200.                return true;
  201.          }
  202.       }
  203.  
  204.       return super.handleEvent(var1);
  205.    }
  206.  
  207.    public void update(Graphics var1) {
  208.       this.paint(var1);
  209.    }
  210.  
  211.    public void paint(Graphics var1) {
  212.       if (this.spComponent != null) {
  213.          this.placeComponents();
  214.       }
  215.    }
  216.  
  217.    public void scrollUp() {
  218.       this.yCoord += this.scrollLineIncrement;
  219.       if (this.yCoord > 0) {
  220.          this.yCoord = 0;
  221.       }
  222.  
  223.       this.VBar.setValue(-this.yCoord);
  224.       ((Component)this).repaint();
  225.    }
  226.  
  227.    public void scrollLeft() {
  228.       this.xCoord += this.scrollLineIncrement;
  229.       if (this.xCoord > 0) {
  230.          this.xCoord = 0;
  231.       }
  232.  
  233.       this.HBar.setValue(-this.xCoord);
  234.       ((Component)this).repaint();
  235.    }
  236.  
  237.    public void scrollDown() {
  238.       this.yCoord -= this.scrollLineIncrement;
  239.       if (-this.yCoord > this.VBar.getMaximum()) {
  240.          this.yCoord = -this.VBar.getMaximum();
  241.       }
  242.  
  243.       this.VBar.setValue(-this.yCoord);
  244.       ((Component)this).repaint();
  245.    }
  246.  
  247.    public void scrollRight() {
  248.       this.xCoord -= this.scrollLineIncrement;
  249.       if (-this.xCoord > this.HBar.getMaximum()) {
  250.          this.xCoord = -this.HBar.getMaximum();
  251.       }
  252.  
  253.       this.HBar.setValue(-this.xCoord);
  254.       ((Component)this).repaint();
  255.    }
  256.  
  257.    public void scrollPageUp() {
  258.       this.yCoord += this.vPageSize;
  259.       if (this.yCoord > 0) {
  260.          this.yCoord = 0;
  261.       }
  262.  
  263.       this.VBar.setValue(-this.yCoord);
  264.       ((Component)this).repaint();
  265.    }
  266.  
  267.    public void scrollPageLeft() {
  268.       this.xCoord += this.hPageSize;
  269.       if (this.xCoord > 0) {
  270.          this.xCoord = 0;
  271.       }
  272.  
  273.       this.HBar.setValue(-this.xCoord);
  274.       ((Component)this).repaint();
  275.    }
  276.  
  277.    public void scrollPageDown() {
  278.       this.yCoord -= this.vPageSize;
  279.       if (-this.yCoord > this.VBar.getMaximum()) {
  280.          this.yCoord = -this.VBar.getMaximum();
  281.       }
  282.  
  283.       this.VBar.setValue(-this.yCoord);
  284.       ((Component)this).repaint();
  285.    }
  286.  
  287.    public void scrollPageRight() {
  288.       this.xCoord -= this.hPageSize;
  289.       if (-this.xCoord > this.HBar.getMaximum()) {
  290.          this.xCoord = -this.HBar.getMaximum();
  291.       }
  292.  
  293.       this.HBar.setValue(-this.xCoord);
  294.       ((Component)this).repaint();
  295.    }
  296.  
  297.    public void scrollVerticalAbsolute(int var1) {
  298.       this.yCoord = -var1;
  299.       if (this.yCoord > 0) {
  300.          this.yCoord = 0;
  301.       } else if (-this.yCoord > this.VBar.getMaximum()) {
  302.          this.yCoord = -this.VBar.getMaximum();
  303.       }
  304.  
  305.       this.VBar.setValue(-this.yCoord);
  306.       ((Component)this).repaint();
  307.    }
  308.  
  309.    public void scrollHorizontalAbsolute(int var1) {
  310.       this.xCoord = -var1;
  311.       if (this.xCoord > 0) {
  312.          this.xCoord = 0;
  313.       } else if (-this.xCoord > this.HBar.getMaximum()) {
  314.          this.xCoord = -this.HBar.getMaximum();
  315.       }
  316.  
  317.       this.HBar.setValue(-this.xCoord);
  318.       ((Component)this).repaint();
  319.    }
  320.  
  321.    public Dimension preferredSize() {
  322.       Dimension var1 = ((Component)this).size();
  323.       Dimension var2 = this.minimumSize();
  324.       return new Dimension(Math.max(var1.width, var2.width), Math.max(var1.height, var2.height));
  325.    }
  326.  
  327.    public Dimension minimumSize() {
  328.       return new Dimension(this.width, this.height);
  329.    }
  330.  
  331.    public Component add(Component var1) {
  332.       this.setComponent(var1);
  333.       ((Component)this).repaint();
  334.       return var1;
  335.    }
  336.  
  337.    public synchronized Component add(Component var1, int var2) {
  338.       return this.add(var1);
  339.    }
  340.  
  341.    public synchronized Component add(String var1, Component var2) {
  342.       return this.add(var2);
  343.    }
  344.  
  345.    public synchronized void remove(Component var1) {
  346.       if (var1 != this.VBar && var1 != this.HBar) {
  347.          super.remove(var1);
  348.          if (var1 == this.spComponent) {
  349.             this.spComponent = null;
  350.          }
  351.  
  352.       }
  353.    }
  354.  
  355.    private void addInternalComponents() {
  356.       super.add(this.VBar, -1);
  357.       super.add(this.HBar, -1);
  358.       super.add(this.cornerRect, -1);
  359.    }
  360.  
  361.    public synchronized void removeAll() {
  362.       super.removeAll();
  363.       this.addInternalComponents();
  364.       this.spComponent = null;
  365.    }
  366.  
  367.    public void setLayout(LayoutManager var1) {
  368.    }
  369.  
  370.    public synchronized void reshape(int var1, int var2, int var3, int var4) {
  371.       ((Component)this).repaint();
  372.       super.reshape(var1, var2, var3, var4);
  373.    }
  374.  
  375.    void placeComponents() {
  376.       byte var3 = 0;
  377.       byte var4 = 0;
  378.       byte var5 = 0;
  379.       this.dimComponent = this.spComponent.size();
  380.       Rectangle var6 = ((Component)this).bounds();
  381.       if (OS.isSolaris()) {
  382.          var3 = 17;
  383.       } else if (OS.isMacintosh()) {
  384.          var3 = 16;
  385.       } else {
  386.          var3 = 15;
  387.       }
  388.  
  389.       boolean var2;
  390.       if (this.bAllowShowHBar && this.dimComponent.width > var6.width) {
  391.          var2 = true;
  392.          var5 = var3;
  393.       } else {
  394.          var2 = false;
  395.          var5 = 0;
  396.       }
  397.  
  398.       boolean var1;
  399.       if (this.bAllowShowVBar && this.dimComponent.height > var6.height - var5) {
  400.          var1 = true;
  401.          var4 = var3;
  402.          if (!var2 && this.dimComponent.width > var6.width - var3) {
  403.             var2 = true;
  404.             var5 = var3;
  405.          }
  406.       } else {
  407.          var1 = false;
  408.          var4 = 0;
  409.       }
  410.  
  411.       this.hPageSize = var6.width - var4 - this.vGapWid;
  412.       this.vPageSize = var6.height - var5 - this.hGapHt;
  413.       if (var1) {
  414.          this.VBar.reshape(var6.width - var3, 0, var3, var6.height - var5);
  415.          this.VBar.setValues(-this.yCoord, this.vPageSize, 0, this.dimComponent.height - this.vPageSize);
  416.          this.VBar.setPageIncrement(this.vPageSize);
  417.          if (!this.bVBarVisible) {
  418.             this.bVBarVisible = true;
  419.             this.VBar.show();
  420.          }
  421.       } else {
  422.          if (this.bVBarVisible) {
  423.             this.bVBarVisible = false;
  424.             this.VBar.hide();
  425.          }
  426.  
  427.          this.yCoord = 0;
  428.       }
  429.  
  430.       if (var2) {
  431.          this.HBar.reshape(0, var6.height - var3, var6.width - var4, var3);
  432.          this.HBar.setValues(-this.xCoord, this.hPageSize, 0, this.dimComponent.width - this.hPageSize);
  433.          this.HBar.setPageIncrement(this.hPageSize);
  434.          if (!this.bHBarVisible) {
  435.             this.bHBarVisible = true;
  436.             this.HBar.show();
  437.          }
  438.       } else {
  439.          if (this.bHBarVisible) {
  440.             this.bHBarVisible = false;
  441.             this.HBar.hide();
  442.          }
  443.  
  444.          this.xCoord = 0;
  445.       }
  446.  
  447.       if (this.bHBarVisible && this.bVBarVisible) {
  448.          int var7 = var6.width - var4;
  449.          int var8 = var6.height - var5;
  450.          int var9 = var6.width - var7 + 1;
  451.          int var10 = var6.height - var8 + 1;
  452.          this.cornerRect.reshape(var7, var8, var9, var10);
  453.          if (!this.bCornerRectVisible) {
  454.             this.bCornerRectVisible = true;
  455.             this.cornerRect.show();
  456.          }
  457.       } else if (this.bCornerRectVisible) {
  458.          this.bCornerRectVisible = false;
  459.          this.cornerRect.hide();
  460.       }
  461.  
  462.       this.spComponent.move(this.xCoord, this.yCoord);
  463.       this.spComponent.validate();
  464.    }
  465. }
  466.